declare global {
    interface RouterMeta {
        title: string;
    }

    interface Router {
        path: string;
        name: string;
        icon?: string;
        permission?: string;
        meta?: RouterMeta;
        component: any;
        children?: Router[];
        props?: any;
    }

    interface System {
        import(request: string): Promise<any>;
    }

    var System: System;
}


import main from '@/views/main.vue';



export const loginRouter: Router = {
    path: '/',
    name: 'login',
    meta: {
        title: '登录',
    },
    component: () => import('@/views/login.vue'),
};

export const otherRouters: Router = {
    path: '/main',
    name: 'main',
    permission: '',
    meta: {
        title: '其他',
    },
    component: main,
    children: [
        {
            path: 'home',
            meta: {
                title: '主页',
            },
            name: 'home',
            component: () => import('@/views/home.vue'),

        },
        {
            path: 'notification',
            meta: {
                title: '通知中心',
            },
            name: 'notification',
            component: () => import('@/views/other/notification/notification.vue'),
        },
    ],
};

export const flowInstanceRouters: Router = {
    path: '/flow-instance-operation',
    name: 'flow-instance-operation',
    permission: '',
    meta: {
        title: '流程中心',
    },
    component: main,
    children: [
        {
            path: 'flow-instance-insert/:which/:id',
            meta: {
                title: '启动流程',
            },
            name: 'flow-instance-insert',
            permission:'Pages.FlowInstances.Launch',
            component: () => import('@/views/flow/flow-instance/flow-instance-insert.vue'),
        },
        {
            path: 'flow-instance-detail/:which/:id',
            meta: {
                title: '流程详情',
            },
            permission:'Pages.FlowInstances.Display',
            name: 'flow-instance-detail',
            component: () => import('@/views/flow/flow-instance/flow-instance-detail.vue'),
        },
    ],
};
export const flowSchemeRouters: Router = {
    path: '/flow-scheme-operation',
    name: 'flow-scheme-operation',
    permission: '',
    meta: {
        title: '系统管理',
    },
    component: main,
    children: [
        {
            path: 'flow-scheme-insert',
            meta: {
                title: '新建流程模板',
            },
            permission:'Pages.Administration.FlowSchemes.Create',
            name: 'flow-scheme-insert',
            component: () => import('@/views/flow/flow-scheme/flow-scheme-insert.vue'),
        },
        {
            path: 'flow-scheme-update/:id',
            meta: {
                title: '更新流程模板',
            },
            permission:'Pages.Administration.FlowSchemes.Update',
            name: 'flow-scheme-update',
            component: () => import('@/views/flow/flow-scheme/flow-scheme-update.vue'),
        },
    ],
};

export const formSchemeRouters: Router = {
    path: '/form-scheme-operation',
    name: 'form-scheme-operation',
    permission: '',
    meta: {
        title: '系统管理',
    },
    component: main,
    children: [
        {
            path: 'form-scheme-insert',
            meta: {
                title: '新建表单模板',
            },
            permission:'Pages.Administration.FormSchemes.Create',
            name: 'form-scheme-insert',
            component: () => import('@/views/form/form-scheme/form-scheme-insert.vue'),
        },
        {
            path: 'form-scheme-update/:id',
            meta: {
                title: '更新表单模板',
            },
            permission:'Pages.Administration.FormSchemes.Update',
            name: 'form-scheme-update',
            component: () => import('@/views/form/form-scheme/form-scheme-update.vue'),
        },
    ],
};

export const appRouters: Router[] = [
    {
        path: '/flow-instance',
        name: 'flow-instance',
        permission: '',
        meta: {
            title: '流程中心',
        },
        icon: 'fa-th',
        component: main,
        children: [
            {
                path: 'launch',
                permission:'Pages.FlowInstances',
                meta: {
                    title: '我发起的流程',
                },
                icon: 'fa-send',
                name: 'launch',
                component: () => import('@/views/flow/flow-instance/flow-instance.vue'),
                props: {type: 'launch'}
            },
            {
                path: 'finished',
                permission:'Pages.FlowInstances',
                meta: {
                    title: '已处理的流程',
                },
                icon: 'fa-archive',
                name: 'finished',
                component: () => import('@/views/flow/flow-instance/flow-instance.vue'),
                props: {type: 'finished'}
            },
            {
                path: 'backlog',
                permission:'Pages.FlowInstances',
                meta: {
                    title: '待处理的流程',
                },
                icon: 'fa-bell',
                name: 'backlog',
                component: () => import('@/views/flow/flow-instance/flow-instance.vue'),
                props: {type: 'backlog'}
            },
            {
                path: 'draft',
                permission:'Pages.FlowInstances',
                meta: {
                    title: '草稿箱',
                },
                icon: 'fa-recycle',
                name: 'draft',
                component: () => import('@/views/flow/flow-instance/flow-instance.vue'),
                props: {type: 'draft'}
            },
            {
                path: 'copy',
                permission:'Pages.FlowInstances',
                meta: {
                    title: '抄送给我的',
                },
                icon: 'fa-send-o',
                name: 'copy',
                component: () => import('@/views/flow/flow-instance/flow-instance.vue'),
                props: {type: 'copy'}
            },
        ],
    },
    {
        path:'/book',
        name:'book',
        permission:'',
        meta:{
            title:'图书'
        },
        icon:'fa-book',
        component:main,
        children:[
            {
                path:'_book',
                permission:'Pages.Books',
                meta:{
                    title:'图书管理',
                },
                icon:'fa-book',
                name:'_book',
                component:()=>import('@/views/book/book.vue'),
            },
        ],
    },
    {
        path: '/administration',
        name: 'administration',
        permission: '',
        meta: {
            title: '系统管理',
        },
        icon: 'fa-cogs',
        component: main,
        children: [
            {
                path: 'organizationUnit',
                permission: 'Pages.Administration.OrganizationUnits',
                meta: {
                    title: '单位',
                },
                icon: 'fa-building',
                name: 'organizationUnit',
                component: () => import('@/views/administration/organization-unit/organization-unit.vue'),
            },
            {
                path: 'user',
                permission: 'Pages.Administration.Users',
                meta: {
                    title: '用户',
                },
                icon: 'fa-user',
                name: 'user',

                component: () => import('@/views/administration/user/user.vue'),
            },
            {
                path: 'role',
                permission: 'Pages.Administration.Roles',
                meta: {
                    title: '角色',
                },
                icon: 'fa-group',
                name: 'role',

                component: () => import('@/views/administration/role/role.vue'),
            },
            {
                path: 'dictionary',
                permission: 'Pages.Administration.Dictionaries',
                meta: {
                    title: '字典',
                },
                icon: 'fa-book',
                name: 'dictionary',
                component: () => import('@/views/administration/dictionary/dictionary.vue'),
            },
            {
                path:'form-scheme',
                permission:'Pages.Administration.FormSchemes',
                meta:{
                    title:'表单',
                },
                icon:'fa-pencil-square',
                name:'form-scheme',
                component:()=>import('@/views/form/form-scheme/form-scheme.vue'),
            },
            {
                path: 'flow-scheme',
                permission: 'Pages.Administration.FlowSchemes',
                meta: {
                    title: '流程',
                },
                icon: 'fa-th-large',
                name: 'flow-scheme',

                component: () => import('@/views/flow/flow-scheme/flow-scheme.vue'),
            },
            {
                path: 'audit-log',
                permission: 'Pages.Administration.Audits',
                meta: {
                    title: '审计日志',
                },
                icon: 'fa-file-text',
                name: 'audit-log',

                component: () => import('@/views/administration/audit-log/audit-log.vue'),
            },
            {
                path: 'maintenance',
                permission: 'Pages.Administration.Maintenances',
                meta: {
                    title: '维护',
                },
                icon: 'fa-gavel',
                name: 'maintenance',

                component: () => import('@/views/administration/maintenance/maintenance.vue'),
            },
            {
                path: 'setting',
                permission: 'Pages.Administration.Settings',
                meta: {
                    title: '设置',
                },
                icon: 'fa-cog',
                name: 'setting',

                component: () => import('@/views/administration/setting/setting.vue'),
            },
        ],
    },
];
export const routers = [
    loginRouter,

    otherRouters,
    flowInstanceRouters,
    flowSchemeRouters,
    formSchemeRouters,
    ...appRouters,
];
